package array;

import java.util.Arrays;
import java.util.Random;

public class ArrayTest {

    private static final Random random = new Random();

    static final String[] fruits = {"apple","pear","peach","banana","photo","good"};


    public static final String[] getFruitsByLimit(int size){
        if(size > fruits.length){
            throw new RuntimeException("size too  big");
        }
        String[] results = new String[size];
        boolean[] flags = new boolean[fruits.length];
        for(int i = 0 ; i < size;i++){
            int t;
            do {
                t = random.nextInt(fruits.length);
            }while(flags[t]);{
                results[i] = fruits[t];
                flags[t] = true;
            }
        }
        return results;
    }

    public static void main(String[] args) {
        for(int i = 0;i<5;i++){
            System.out.println(Arrays.asList(getFruitsByLimit(6)));
        }
    }


}
